﻿using CommunityToolkit.Mvvm.ComponentModel;

using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace GeTuiPushDemo.ViewModels;

public abstract partial class BaseViewModel: INotifyPropertyChanged
{
    protected bool SetProperty<T>
            (ref T backingStore,
            T value,
            [CallerMemberName] string propertyName = "",
            Action onChanged = null)
    {
        if (EqualityComparer<T>.Default.Equals(backingStore, value))
        {
            return false;
        }
        backingStore = value;
        onChanged?.Invoke();
        NotifyPropertyChanged(propertyName);
        return true;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
    {
        this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public virtual void ExecuteOnDisappearing()
    {

    }

    public virtual void ExecuteOnAppearing()
    {

    }
}